/*  This file is part of -_-.

    -_- is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    -_- is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with -_-.  If not, see <http://www.gnu.org/licenses/>.

    Copyright 2012-2013 Oliver Katz */

#ifndef __COMMON_EXCSTACK_H
#define __COMMON_EXCSTACK_H

#include <stdio.h>
#include <string.h>
#include <malloc.h>

//struct z_excframe: one frame in an execution stack (internal use only)
typedef struct 
{
    char *fname; //memberof z_excframe: the name of the function
    int rc; //memberof z_excframe: the return code of the function
    char *rd; //memberof z_excframe: the description of this return code
} z_excframe;

z_excframe z_excframe_init(char *f, int r, char *d); //methodof z_excframe: initializer
//argof z_excframe_init: char *f: the function name
//argof z_excframe_init: int r: the return code
//argof z_excframe_init: char *d: the description
int z_excframe_release(z_excframe f); //methodof z_excframe: uninitializer
char *z_excframe_function_get(z_excframe *f); //methodof z_excframe: gets the function name
int z_excframe_returncode_get(z_excframe *f); //methodof z_excframe: gets the return code
char *z_excframe_description_get(z_excframe *f); //methodof z_excframe: gets the description
int z_excframe_dump(z_excframe *f); //methodof z_excframe: displays the frame (used for stacktraces)

#define Z_EXCSTACK_SIZE 512
#define Z_EXCSTACK_PUSH(f, r, d) z_excstack_push(z_excframe_init(f, r, d))

extern z_excframe *_z_excstack;
extern z_excframe *_z_exchead;

int z_excstack_init(); //method: initialize the execution stack
int z_excstack_push(z_excframe f); //method: push a new frame onto the execution stack
int z_excstack_dump(); //method: display the execution stack (print stacktrace)

#endif